package com.itheima;

import java.util.Random;
import java.util.Scanner;

public class Java_08 {
    public static void main(String[] args) {
        //案例：抢红包
        int[] temp = new int[]{999,222,111,2000,2233};
        start(temp);
    }
    //定义一个抢红包的方法
    public static void start(int[] numbers){
        Random r = new Random();
        Scanner sc = new Scanner(System.in);
        //遍历数组，随机产生一个数组的索引值

           for (int i = 0; i < numbers.length;i++ ) {
               while (true){
                   int index = r.nextInt(numbers.length);
                   System.out.println("请输入任意一个内容：");
                   sc.next();
                   int money = numbers[index];
                   //判断用户是否抢到0的红包
                   if (money != 0){
                       System.out.println("恭喜您，抢到的红包金额为："+money);
                       numbers[index] = 0;
                       break;
                       }
                   if (money==0){break;}
                   else{
                       i--;
               }

           }
                }
    }
}
